package com.neuedu.controller;


import com.neuedu.common.Constants;
import com.neuedu.pojo.Result;
import com.neuedu.pojo.TAccount;
import com.neuedu.service.ITAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhangsan
 * @since 2024-06-17
 */
@RestController
@RequestMapping("/account")
public class TAccountController {
    @Autowired
    ITAccountService accountService;

    @PostMapping("/login")
    public Result login(String username, String password) throws UnsupportedEncodingException {
        List<TAccount> accounts = accountService.login(username, password);
        if (accounts.isEmpty() || accounts == null) {
            return Result.fail(Constants.LOGIN_FAIL);
        }
        return Result.success(accounts, Constants.LOGIN_SUCCESS);
    }
   @PostMapping("/edit")
    public Result modifyacc(@RequestBody TAccount account){
        return accountService.changeacc(account);
   }
}
